<?php
	//支付宝支付接口-alipay.php
	//create by L
	//http://42.121.57.193:7788/platform/alipay.php?phone=13222422341&money=30
	//初始化--
	include_once "init.php";

	$phone        	= $_GET["phone"];
	$money        = $_GET["money"];


	if('' == $phone )
	{
		die("-1|手机号码不可以为空");
	}
	if ('' == $money)
	{
		die("-1|充值金额不能为空");
	}

	if (false==is_numeric($money))
	{
		die("-1|充值金额必须为数字");
	}

	if (strlen($phone) != 11 || false==is_numeric($phone) || ord($phone)!=49)
	{
		die("-1|手机号码必须是11位数字，并且以1开头");
	}

	$flag 			= 0;
	$create_time 	= date('Y-m-d H:i:s');
	$con = db_connect(DB_NAME);

	//--创建一个新订单
	mysql_query("LOCK TABLES alipay WRITE");
	mysql_query("INSERT INTO alipay (phone,money,flag,create_time) VALUES ('".$phone."','".$money."','".$flag."','".$create_time."')");
	$result=mysql_query("SELECT LAST_INSERT_ID() AS uuid");
	mysql_query("UNLOCK TABLES");

	if(FALSE==$result)
	{
		mysql_close($con);
		die("-1|数据库生成订单失败");
	}

	$row = mysql_fetch_array($result);

	if(empty($row))
	{
		mysql_close($con);
		die("-1|获取订单失败");
	}
	mysql_close($con);
	//生成唯一订单号-用于返回给客户端
	$list_no = $row['uuid'];

	echo '0|'.$list_no.'|'.ALI_PAY_RESULT_URL;

?>
